/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.InternalEList;

import reamodel.EconomicAgent;
import reamodel.EconomicAgentType;
import reamodel.ProvideParticipation;
import reamodel.ReamodelPackage;
import reamodel.ReceiveParticipation;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Economic Agent</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.EconomicAgentImpl#getProvides <em>Provides</em>}</li>
 *   <li>{@link reamodel.impl.EconomicAgentImpl#getReceives <em>Receives</em>}</li>
 *   <li>{@link reamodel.impl.EconomicAgentImpl#getName <em>Name</em>}</li>
 *   <li>{@link reamodel.impl.EconomicAgentImpl#getTypifiedBy <em>Typified By</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class EconomicAgentImpl extends EObjectImpl implements EconomicAgent {
	/**
	 * The cached value of the '{@link #getProvides() <em>Provides</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProvides()
	 * @generated
	 * @ordered
	 */
	protected EList<ProvideParticipation> provides;

	/**
	 * The cached value of the '{@link #getReceives() <em>Receives</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReceives()
	 * @generated
	 * @ordered
	 */
	protected EList<ReceiveParticipation> receives;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getTypifiedBy() <em>Typified By</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTypifiedBy()
	 * @generated
	 * @ordered
	 */
	protected EconomicAgentType typifiedBy;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EconomicAgentImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.ECONOMIC_AGENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ProvideParticipation> getProvides() {
		if (provides == null) {
			provides = new EObjectContainmentWithInverseEList<ProvideParticipation>(ProvideParticipation.class, this, ReamodelPackage.ECONOMIC_AGENT__PROVIDES, ReamodelPackage.PROVIDE_PARTICIPATION__AGENT);
		}
		return provides;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ReceiveParticipation> getReceives() {
		if (receives == null) {
			receives = new EObjectContainmentWithInverseEList<ReceiveParticipation>(ReceiveParticipation.class, this, ReamodelPackage.ECONOMIC_AGENT__RECEIVES, ReamodelPackage.RECEIVE_PARTICIPATION__AGENT);
		}
		return receives;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_AGENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicAgentType getTypifiedBy() {
		if (typifiedBy != null && typifiedBy.eIsProxy()) {
			InternalEObject oldTypifiedBy = (InternalEObject)typifiedBy;
			typifiedBy = (EconomicAgentType)eResolveProxy(oldTypifiedBy);
			if (typifiedBy != oldTypifiedBy) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY, oldTypifiedBy, typifiedBy));
			}
		}
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EconomicAgentType basicGetTypifiedBy() {
		return typifiedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTypifiedBy(EconomicAgentType newTypifiedBy, NotificationChain msgs) {
		EconomicAgentType oldTypifiedBy = typifiedBy;
		typifiedBy = newTypifiedBy;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY, oldTypifiedBy, newTypifiedBy);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTypifiedBy(EconomicAgentType newTypifiedBy) {
		if (newTypifiedBy != typifiedBy) {
			NotificationChain msgs = null;
			if (typifiedBy != null)
				msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.ECONOMIC_AGENT_TYPE__TYPIFY, EconomicAgentType.class, msgs);
			if (newTypifiedBy != null)
				msgs = ((InternalEObject)newTypifiedBy).eInverseAdd(this, ReamodelPackage.ECONOMIC_AGENT_TYPE__TYPIFY, EconomicAgentType.class, msgs);
			msgs = basicSetTypifiedBy(newTypifiedBy, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY, newTypifiedBy, newTypifiedBy));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getProvides()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getReceives()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				if (typifiedBy != null)
					msgs = ((InternalEObject)typifiedBy).eInverseRemove(this, ReamodelPackage.ECONOMIC_AGENT_TYPE__TYPIFY, EconomicAgentType.class, msgs);
				return basicSetTypifiedBy((EconomicAgentType)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				return ((InternalEList<?>)getProvides()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				return ((InternalEList<?>)getReceives()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				return basicSetTypifiedBy(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				return getProvides();
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				return getReceives();
			case ReamodelPackage.ECONOMIC_AGENT__NAME:
				return getName();
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				if (resolve) return getTypifiedBy();
				return basicGetTypifiedBy();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				getProvides().clear();
				getProvides().addAll((Collection<? extends ProvideParticipation>)newValue);
				return;
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				getReceives().clear();
				getReceives().addAll((Collection<? extends ReceiveParticipation>)newValue);
				return;
			case ReamodelPackage.ECONOMIC_AGENT__NAME:
				setName((String)newValue);
				return;
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				setTypifiedBy((EconomicAgentType)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				getProvides().clear();
				return;
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				getReceives().clear();
				return;
			case ReamodelPackage.ECONOMIC_AGENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				setTypifiedBy((EconomicAgentType)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.ECONOMIC_AGENT__PROVIDES:
				return provides != null && !provides.isEmpty();
			case ReamodelPackage.ECONOMIC_AGENT__RECEIVES:
				return receives != null && !receives.isEmpty();
			case ReamodelPackage.ECONOMIC_AGENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ReamodelPackage.ECONOMIC_AGENT__TYPIFIED_BY:
				return typifiedBy != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //EconomicAgentImpl
